<template>
  <jl-base>
    <jl-header>
      <mt-header title="修改密码" :fixed="true">
        <i slot="left">
          <mt-button icon="back" @click="back"></mt-button>
        </i>
      </mt-header>
    </jl-header>

    <jl-content>
       <span class="mt20 mb20 pl15 pr15 font_size_large font_black_999">
        修改密码后，可用新密码登录APP。
    </span>
      <div class="w12 bgcolor_white">
        <div class="jl_input">
          <div class="jl_input_item pr15">
            <span class="w04">原密码</span>
            <nut-textinput
              v-model="password"
              class="w07"
              placeholder="原密码"
              type="password"
            />
          </div>
        </div>
      </div>
      <div class="w12 bgcolor_white mt15">
        <div class="jl_input">
          <div class="jl_input_item bor_bottom pr15">
            <span class="w04">新密码</span>
            <nut-textinput
              v-model="new_password"
              class="w07"
              placeholder="请设置新密码"
              type="password"
            />
          </div>
        </div>
        <div class="jl_input">
          <div class="jl_input_item pr15">
            <span class="w04">确认密码</span>
            <nut-textinput
              v-model="check_new_password"
              class="w07"
              placeholder="请在次输入密码"
              type="password"
            />
          </div>
        </div>
      </div>
    </jl-content>

    <jl-footer>
      <div class="footer_btn">
        <button @click="save" style="width: 90vw; !important;">提交</button>
      </div>
    </jl-footer>
  </jl-base>
</template>

<script>
  export default {
    name: "MyChangePassword",
    data() {
      return {
        password: '',
        new_password: '',
        check_new_password: '',
        olddlmm: '',
      }
    },
    methods: {
      back() {
        this.$router.back()
      },
      save() {
        if (this.password != this.olddlmm) {
          $Utils.MessageBox.confirm('输入的原密码不对!');
          return;
        }
        if (this.new_password != this.check_new_password) {
          $Utils.MessageBox.confirm('输入的确认密码和新密码不一致!')
          return;
        }

        this.updatePassword()
      },
      updatePassword() {
        let userInfo = $Utils.getUserInfo();
        this.http.post('/api/user/updateMM.do', {
          XmlData: {
            CZY01: userInfo['PCRM_CZY02'],
            CZY02: this.new_password,
          }
        })
          .then(v => {
            if (v['data']['STATE'] == 1) {
              $Utils.MessageBox.confirm('修改密码成功');
              this.back();
            } else {
              $Utils.MessageBox.confirm('修改密码失败');
            }
          })
          .catch()
      }
    },
    created() {
      this.$engineer.searchPassword()
        .then(v => {
          this.olddlmm = v['password'];
        })
    }
  }
</script>

<style scoped>

</style>
